package com.visionblue.business.ship.page.dialog

import android.app.Activity
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kennyc.view.MultiStateView
import com.visionblue.business.ship.R
import com.visionblue.business.ship.model.bean.response.TransportShipInfo

/**
 * @author: xlh
 * @date: 2020-06-08 4:59 PM
 * @desc:
 */
class SelectionTransportDialog(context: Activity) {

    private val mDialog: BlurrySlideDialog = BlurrySlideDialog(
        context,
        R.layout.dialog_selection_transport
    )


    fun showContent(
        data: List<TransportShipInfo>,
        onItemClickListener: SelectionTransportAdapter.OnItemClickListener
    ) {
        mDialog.findViewById<MultiStateView>(R.id.multiStateView).viewState =
            MultiStateView.ViewState.CONTENT

        val rvTransporters = mDialog.findViewById<RecyclerView>(R.id.rvTransporters)
        rvTransporters.layoutManager = LinearLayoutManager(mDialog.context)
        rvTransporters.adapter = SelectionTransportAdapter(data).apply {
            this.onItemClickListener = object : SelectionTransportAdapter.OnItemClickListener {
                override fun onItemClick(shipNo: String?) {
                    mDialog.dismiss()
                    onItemClickListener.onItemClick(shipNo)
                }
            }
        }

    }

    fun showEmpty() {
        mDialog.findViewById<MultiStateView>(R.id.multiStateView).viewState =
            MultiStateView.ViewState.EMPTY
        mDialog.findViewById<ImageView>(R.id.ivClose).setOnClickListener {
            mDialog.dismiss()
        }
        mDialog.show()
    }

    fun showError() {
        mDialog.findViewById<MultiStateView>(R.id.multiStateView).viewState =
            MultiStateView.ViewState.ERROR

        mDialog.findViewById<ImageView>(R.id.ivClose).setOnClickListener {
            mDialog.dismiss()
        }
    }

    fun showLoading() {
        mDialog.findViewById<MultiStateView>(R.id.multiStateView).viewState =
            MultiStateView.ViewState.LOADING

        mDialog.findViewById<ImageView>(R.id.ivClose).setOnClickListener {
            mDialog.dismiss()
        }
        mDialog.show()
    }


}